package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.ProductPlanSonView;
import com.sl.au.repository.ProductPlanSonViewRepository;
import com.sl.au.service.ProductPlanSonViewService;
@Service("ProductPlanSonViewService")
@Transactional
public class ProductPlanSonViewServiceImpl extends BaseServiceImpl implements ProductPlanSonViewService{
	@Autowired
	ProductPlanSonViewRepository productPlanSonViewRepository;

	@Override
	public List<ProductPlanSonView> getMyPage(int start, int length, int key) {
		// TODO Auto-generated method stub
		Page<ProductPlanSonView> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"cOrderNumber");//排序
		if(key == 0){
			pages=productPlanSonViewRepository.getPage( pageable);
		}else{
			pages=productPlanSonViewRepository.getPage(key, pageable);
		}
		return pages.getContent();
	}

	@Override
	public long getCount(int key) {
		// TODO Auto-generated method stub
		long count = 0;
		if(key == 0){
			count = productPlanSonViewRepository.getCount();
		}else{
			count = productPlanSonViewRepository.getCount(key);
		}
		return count;
	}

	@Override
	public ProductPlanSonViewRepository getRepository() {
		// TODO Auto-generated method stub
		return this.productPlanSonViewRepository;
	}
	
	
}
